﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Agency_TraTradeDataList : System.Web.UI.Page, HZ.MBSM.BLL.TraDes
{
    public string strConditions, field_name = "SupplyGoodsId", strVistia = "";
    public int projectid;
    bool IsPrint = false;
    protected void Page_Load(object sender, EventArgs e)
    {

        if (HZ.MBSM.BLL.Login.CheckAssert(this.UseAccountType))
        {
            projectid = SysFun.ToInt(SysFun.IsSQL(Request.QueryString["projectid"]));
           
            if (!IsPostBack)
            {
  
                lstGoodsState.Items.Add("全部");
                //lstGoodsState.Items.Add("原中标");
                //lstGoodsState.Items.Add("自行采购");
               // lstGoodsState.Items.Add("22种降价");
                //lstGoodsState.Items.Add("血液制品");
               // lstGoodsState.Items.Add("重点监控");
                HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
                if (_Account.Type == "4")
                {
                    strVistia = "none";
                   
                }
                else
                {
                    strVistia = "inline-block";
                   
                }


            }  
            switch (projectid.ToString())
            {
                case "8":  
                    GridView1.Columns[9].HeaderText = "中标价";
                    GridView1.Columns[10].HeaderText = "最高零售价";
                    break;
                case "9":
                    GridView1.Columns[9].HeaderText = "最高零售价";
                    GridView1.Columns[10].Visible = false;
                    break;
                case "10":
                    GridView1.Columns[9].HeaderText = "最高限价";
                    GridView1.Columns[10].HeaderText = "最高零售价";
                    break;
                case "11":
                    GridView1.Columns[9].Visible = false;
                    GridView1.Columns[10].Visible = false;
                    break;
                case "12":
                    GridView1.Columns[9].HeaderText = "最高零售价";
                    GridView1.Columns[10].Visible = false;
                    break;

            }
            GridView1.Columns[0].Visible = true;
            showGridView();
            GridView1.Columns[0].Visible = false;

          
        }

    }
   
    /// <summary>
    /// 数据绑定
    /// </summary>
    public void showGridView()
    {
        
        //0 原中标商品 1 自行采购  2  22种降价 3 人血蛋白 4 重点监控 默认为‘0’

        strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "SupplyPlan_Goods";                                               //要查询的表明
        dbPage.Key = "SupplyGoodsId";                                          //表的主键    
        dbPage.Where = strConditions;                                           //查询条件    
        dbPage.SelectField = "unit,Factor,SupplyGoodsId,projectid,productcode,ProductName,MedicineModel,Convert(numeric(20,2),RetailPrice) as RetailPrice,Outlookc,GoodsId,CompanyName_PS,CompanyName_SC,CompanyName_TB,Convert(numeric(20,2),BidPrice) as BidPrice,IsUse,pack,GoodsName,CASE QualityLevels " + ConfigurationManager.AppSettings["QualityLevels"].ToString() + " END AS QualityLevels,case GoodsState when '0' then '原中标' when '1' then '自行采购' when '2' then '22种降价' when '3' then '血液制品' when '4' then '重点监控' end as goodsstate";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        if (!IsPrint)
        {
            dbPage.PageSize = 15;                                                    //没有显示记录条数   
        }
        else
        {
            dbPage.PageSize = 90000000;     
        }
        dbPage.OrderBy = "CompanyName_SC,ProductName";                  //排序字段
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        GridView1.DataSource = dr;
        GridView1.DataBind();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键


    }
    /// <summary>
    /// 生成查询条件
    /// </summary>
    /// <returns></returns>
    public string fctConditions()
    {
        string strtemp = "", ProductName = "", _ProductCode, GoodsState, IsUse, _CompanyName_TB, _CompanyName_SC, ProductNameX="";
        int _GoodsID=1;
        GoodsState = lstGoodsState.SelectedValue.ToString();
        //0 原中标商品 1 自行采购  2  22种降价 3 人血蛋白 4 重点监控 默认为‘0’

        switch (GoodsState)
        {
            case "全部":
                break;
            case "原中标":
                strtemp = " GoodsState=0 and";
                break;
            case "自行采购":
                strtemp = " GoodsState=1 and";
                break;
            case "22种降价":
                strtemp = " GoodsState=2 and";
                break;
            case "血液制品":
                strtemp = " GoodsState=3 and";
                break;
            case "重点监控":
                strtemp = " GoodsState=4 and";
                break;
        }
        //_AccountName_SHR = lstSHR.SelectedValue;
        strtemp = strtemp + " projectid=" + projectid + " and";
        IsUse = lstIsUse.SelectedValue;
        switch (IsUse)
        {
            case "全部":
                break;
            case "撤废状态":
                strtemp = strtemp + " IsUse<>1 and";
                break;
            case "可交易状态":
                strtemp = strtemp + " IsUse=1 and";
                break;
        }
        ProductName = txtProductName.Text.ToString().Trim();
        ProductNameX = TextBox1.Text.Trim();
        _ProductCode = txtProductCode.Text.ToString().Trim();
        _CompanyName_TB = Text_CompanyName_TB.Text.ToString().Trim();
        _CompanyName_SC = Text_CompanyName_SC.Text.ToString().Trim();
        if(Text_GoodsID.Text.ToString().Trim().Length != 0 )
        {
            _GoodsID = Convert.ToInt32(Text_GoodsID.Text);
        }
            
       
        
        if (_ProductCode != "")
        {
            strtemp = strtemp + " ProductCode like '%" + _ProductCode + "%' and";
        }
        if (ProductNameX != "")
        {
            strtemp = strtemp + "(ProductName = '" + ProductNameX + "' or Product_SpellingCode ='" + ProductNameX + "') and";
        }
       if (ProductName != "")
        {
            strtemp = strtemp + "(ProductName like '%" + ProductName + "%' or Product_SpellingCode like'%" + ProductName + "%') and";
        }
        if (_CompanyName_SC != "")
        {
            strtemp = strtemp + " CompanyName_SC like '%" + _CompanyName_SC + "%' and";
        }
        if (_CompanyName_TB != "")
        {
            strtemp = strtemp + " CompanyName_TB like '%" + _CompanyName_TB + "%' and";
        }
        if (Text_GoodsID.Text != "")
        {
            strtemp = strtemp + " GoodsID = '" + _GoodsID + "' and";
        }
        if (strtemp != "")
        {
            strtemp = "  " + strtemp.Substring(0, strtemp.Length - 3);
        }
        return strtemp;
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType != DataControlRowType.Footer && e.Row.RowType != DataControlRowType.Header)
        {
            e.Row.Cells[7].Text = "<a href='UpTradeGoods_detail.aspx?SupplyGoodsId=" + e.Row.Cells[0].Text + "&projectid=" + projectid + "' target=\"_blank\">详情修改</a>";
        }
    }
    protected void ToEcxul_Click(object sender, EventArgs e)
    {
        //0 原中标商品 1 自行采购  2  22种降价 3 人血蛋白 4 重点监控 默认为‘0’



        switch (projectid.ToString())
        {
            case "8":
                GridView1.Columns[9].HeaderText = "中标价";
                GridView1.Columns[10].HeaderText = "最高零售价";
                break;
            case "9":
                GridView1.Columns[9].HeaderText = "最高零售价";
                GridView1.Columns[10].Visible = false;
                break;
            case "10":
                GridView1.Columns[9].HeaderText = "最高限价";
                GridView1.Columns[10].HeaderText = "最高零售价";
                break;
            case "11":
                GridView1.Columns[9].Visible = false;
                GridView1.Columns[10].Visible = false;
                break;
            case "12":
                GridView1.Columns[9].HeaderText = "最高零售价";
                GridView1.Columns[10].Visible = false;
                break;

        }
        IsPrint = true;
        GridView1.Columns[0].Visible = true;
        showGridView();
        GridView1.Columns[0].Visible = false;


        Response.Clear();
        Response.Buffer = true;
        Response.Charset = "GB2312";
        // 添加头信息，为"文件下载/另存为"对话框指定默认文件名 
        Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("挂网目录.xls"));
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
        Response.ContentEncoding = System.Text.Encoding.UTF7;  //解决将gridview导出成excel时出现乱码  
        Response.ContentType = "application/ms-excel";
        this.EnableViewState = false;
        System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
        this.GridView1.RenderControl(oHtmlTextWriter);

         //把文件流发送到客户端 
        Response.Write(oStringWriter.ToString());
      //   停止页面的执行


        Response.End();
     

  }
    public override void VerifyRenderingInServerForm(Control control)
    {
        //OverRide　为了使导出成Excel可行！

    }

    #region TraDes 成员

    public string Name
    {
        get { return "挂网目录列表"; }
    }

    public string Describe
    {
        get { return ""; }
    }

    public string ParentName
    {
        get { return "挂网目录管理"; }
    }

    public System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> UseAccountType
    {
        get
        {
            System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
            return _AccountType;
        }
    }

    #endregion
    protected void Button1_Click(object sender, EventArgs e) //挂网目录修改开关

    {

    }


   
}
